package com.kaifamiao.N0802;

import java.util.Arrays;

public class Node11 implements Stack {

    private char[]chs;
    private  int size = 0;
    public Node11(){
        chs = new char[10];
    }

    public Node11(int size){
        if (size > 0){
            chs = new char[size];
        }else{
            chs = new char[10];
        }
    }

    @Override
    public void push(char ch) {
        if(size == chs.length){
            grow();
        }
        chs[size] = ch;
        size++;
    }

    private void grow(){
        chs = Arrays.copyOf(chs,chs.length +10);
    }

    @Override
    public char pop() {
        char old = chs[size - 1];
        chs[size - 1] = '\u0000';
        size --;
        return old;
    }

    @Override
    public char top() {
        char old1 = chs[size + 1];
        chs[size + 1] = '\u0000';
        size ++;
        return old1;
    }

    @Override
    public int size() {
        return this.size;
    }

    @Override
    public boolean empty() {
        return size == 0;
    }
}
